import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import '../controllers/home_controller.dart';
import 'package:banquanjie_app/app/services/screenAdapter.dart';
import 'package:banquanjie_app/app/widget/work/videoList.dart';
import 'package:banquanjie_app/app/widget/work/scriptList.dart';
import 'package:banquanjie_app/app/widget/work/letterList.dart';
import 'package:banquanjie_app/app/widget/ipElite/card.dart';
import 'package:banquanjie_app/app/widget/company/card.dart';
import 'package:banquanjie_app/app/widget/project/card.dart';
import 'package:banquanjie_app/app/widget/home/title.dart';
class HomeView extends GetView<HomeController> {
  const HomeView({super.key});
  @override
  Widget build(BuildContext context) {
    // 在 build 方法开始时调用 controller 的初始化方法
    return Scaffold(
      appBar: AppBar(
        title: Text('首页', style: TextStyle(fontSize: ScreenAdapter.fontSize(34),color: Colors.black, fontWeight: FontWeight.bold )),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.only(top: ScreenAdapter.width(30)),
        color: Color.fromRGBO(244, 247, 252, 1),
        child: Obx(() => ListView(
          children: [
            AspectRatio(
              aspectRatio: 2.5, 
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(20)),
                // height: ScreenAdapter.width(290),
                width: double.infinity,
                child: Swiper(
                  itemBuilder: (context, index){
                    return ClipRRect(
                      borderRadius: BorderRadius.circular(ScreenAdapter.width(8)),
                      child: Image.network("${controller.bannerList[index]['banner_url']}", fit: BoxFit.cover)
                    );
                  },
                  itemCount: controller.bannerList.length,
                  pagination: const SwiperPagination(builder: SwiperPagination.rect),
                  // control: const SwiperControl(),
                  autoplay: true,
                  loop: true,
                )
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(20)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  for(int i = 0; i < controller.bannerList2.length; i++)
                  Padding(
                    padding: EdgeInsets.only(top: ScreenAdapter.height(36)),
                    child:  InkWell(
                      onTap: () {
                        if (controller.bannerList2[i]['onLink'].isNotEmpty)
                          // ignore: curly_braces_in_flow_control_structures
                          Get.toNamed(controller.bannerList2[i]['onLink']);
                      },
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          ClipRRect(
                            child: Image.network('${controller.bannerList2[i]['img']}', width: ScreenAdapter.width(98), height: ScreenAdapter.width(98))
                          ),
                          SizedBox(height: ScreenAdapter.width(16)),
                          Text('${controller.bannerList2[i]['title']}', style: TextStyle(height:1, fontSize: ScreenAdapter.fontSize(26),color: Color.fromRGBO(29, 28, 28, 1),fontWeight: FontWeight.w500)),
                          SizedBox(height: ScreenAdapter.width(16)),
                        ]
                      )
                    )
                  )
                ]
              )
            ),
            SizedBox(height: ScreenAdapter.height(14)),
            AspectRatio(
              aspectRatio: 2.92,
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(10)),
                // height: ScreenAdapter.height(244),
                width: double.infinity,
                child: Swiper(
                  itemBuilder: (context, index){
                    return Container(
                      padding: EdgeInsets.fromLTRB(ScreenAdapter.width(48), ScreenAdapter.width(22), 0, 0),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: NetworkImage("${controller.uploadList[index]['bg_img']}"),
                          fit: BoxFit.cover
                        )
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Text("${controller.uploadList[index]['title']} “ ", style: TextStyle(height: 1.86, fontSize: ScreenAdapter.fontSize(30),color: Colors.white, fontWeight: FontWeight.bold)),
                              Stack(
                                children: [
                                  for(int i = 0; i < controller.uploadList[index]['avatar'].length; i++)
                                    Align(
                                      alignment: Alignment(i * 10, 0),
                                      child: Image.network("https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/${controller.uploadList[index]['avatar'][i]}.png", width: ScreenAdapter.width(38), height: ScreenAdapter.width(38)),
                                    )
                                ],
                              ),
                              Text("${controller.uploadList[index]['title_desc']}”", style: TextStyle(height: 1.86, fontSize: ScreenAdapter.fontSize(24),color: Colors.white, fontWeight: FontWeight.bold))
                            ]
                          ),
                          // SizedBox(height: ScreenAdapter.height(26)),
                          Text('${controller.uploadList[index]['desc']}', style: TextStyle(height: 2.08, fontSize: ScreenAdapter.fontSize(24),color: Colors.white, fontWeight: FontWeight.w600)),
                          SizedBox(height: ScreenAdapter.width(16)),
                          // SizedBox(height: ScreenAdapter.height(30)),
                          Container(
                            height: ScreenAdapter.width(62),
                            constraints: BoxConstraints(
                              minWidth: ScreenAdapter.width(218), // 设置最小宽度为200像素
                            ),
                            child: ElevatedButton(
                              onPressed: (){},
                              style: ButtonStyle(
                                padding: WidgetStateProperty.all(EdgeInsets.fromLTRB(ScreenAdapter.width(6), 0, ScreenAdapter.width(6), 0)),
                                backgroundColor: WidgetStateProperty.all(Colors.white),
                                shape: WidgetStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(ScreenAdapter.width(6)))),
                              ),
                              child: Text('${controller.uploadList[index]['btn_txt']}', style: TextStyle(fontSize: ScreenAdapter.fontSize(28),color: Colors.black, fontWeight: FontWeight.w500))
                            )
                          )
                        ]
                      )
                    );
                  },
                  itemCount: controller.uploadList.length,
                  // pagination: const SwiperPagination(builder: SwiperPagination.rect),
                  // control: const SwiperControl(),
                  autoplay: false,
                  loop: false,
                )
              )
            ),
            HomeTitle('作品推荐', onTap: () { Get.toNamed('/work-list'); }),
            Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Wrap(
                runSpacing: ScreenAdapter.height(12),
                alignment: WrapAlignment.spaceBetween,
                children: [
                  for (var item in controller.workList)
                    if (item['worksTypeFirst'] == 204) 
                      Scriptlist(item: item)
                    else if (item['worksTypeFirst'] == 205)
                      LetterList(item: item)
                    else 
                      VideoList(item: item)
                ]
              )
            ),
            HomeTitle('入驻精英', onTap: () { Get.toNamed('/ip-elite'); }),
            Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Wrap(
                runSpacing: ScreenAdapter.width(12),
                alignment: WrapAlignment.spaceBetween,
                children: [
                  for (var item in controller.eliteList)
                    EliteCard(item: item)
                ]
              )
            ),
            HomeTitle('合作企业/机构', onTap: () { Get.toNamed('/company-list'); }),
            Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Column(
                spacing: ScreenAdapter.width(12),
                children: [
                  for (var item in controller.companyList)
                    CompanyCard(item: item)
                ]
              )
            ),
            HomeTitle('作品项目', onTap: () { Get.toNamed('/project-list'); }),
             Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Column(
                children: [
                  for (var item in controller.projectList)
                    ProjectCard(item: item)
                ]
              )
            ),
          ],
        ))
      )
    );
  }
}
